/**
 * The Edge class represents an edge in a WUGraph.
 * This class is seperate from the Edge implementation used by
 * the WUGraph class.
 */
class Edge implements Comparable {
  protected Object v1;
  protected Object v2;
  protected int weight;

  /**
   * Edge() constructs a new Edge object representing the undirected
   * edge from v1 to v2 and with weight weight.
   */
  public Edge(Object v1, Object v2, int weight) {
    this.v1 = v1;
    this.v2 = v2;
    this.weight = weight;
  }

  /**
   * getWeight() returns the weight associated with 'this'
   * edge.
   */
  public int getWeight() {
    return weight;
  }

  /**
   * getV1() returns the first vertex associated with this
   * edge object.
   */
  public Object getV1() {
    return v1;
  }

  /**
   * getV2() returns the second vertex associated with this
   * edge object.
   */
  public Object getV2() {
    return v2;
  }

  /**
   * isSameEdge() checks to see if this edge has parameters
   * v1 and v2 as verticies. It returns true if it does.
   * Order does not matter.
   */
  public boolean isSameEdge(Object v1, Object v2) {
    return (v1 == this.v1 && v2 == this.v2) || (v2 == this.v1 && v1 == this.v2);
  }

  /**
   * compareTo() is to implement the Comparable interface. It
   * compares 'this' edge's weight to the weight of edge e.
   */
  public int compareTo(Object e) throws ClassCastException {
    if (!(e instanceof Edge)) {
      throw new ClassCastException("e not an Edge object");
    }
    return this.getWeight() - ((Edge)e).getWeight();
  }
}
